$(document).ready(function(){
//	var info = {
//		"0":{
//			"0":{"id":"第1位","name":"sss","url":"/Public/game/images/0.jpg"},
//			"1":{"id":"第2位","name":"sss","url":"./images/0.jpg"},
//			"2":{"id":"第3位","name":"sss","url":"./images/0.jpg"},
//			"3":{"id":"第4位","name":"sss","url":"./images/0.jpg"},
//			"4":{"id":"第5位","name":"sss","url":"./images/0.jpg"},
//			"5":{"id":"第6位","name":"sss","url":"./images/0.jpg"},
//		},
//		"1":{
//			"0":{"id":"第1位","name":"sss","url":"./images/0.jpg"},
//			"1":{"id":"第2位","name":"sss","url":"./images/0.jpg"},
//			"2":{"id":"第3位","name":"sss","url":"./images/0.jpg"},
//			"3":{"id":"第4位","name":"sss","url":"./images/0.jpg"},
//			"4":{"id":"第5位","name":"sss","url":"./images/0.jpg"},
//			"5":{"id":"第6位","name":"sss","url":"./images/0.jpg"},
//		},
//		"2":{
//			"0":{"id":"第1位","name":"sss","url":"./images/0.jpg"},
//			"1":{"id":"第2位","name":"sss","url":"./images/0.jpg"},
//			"2":{"id":"第3位","name":"sss","url":"./images/0.jpg"},
//			"3":{"id":"第4位","name":"sss","url":"./images/0.jpg"},
//			"4":{"id":"第5位","name":"sss","url":"./images/0.jpg"},
//			"5":{"id":"第6位","name":"sss","url":"./images/0.jpg"},
//		},
//		"3":{
//			"0":{"id":"第1位","name":"sss","url":"./images/0.jpg"},
//			"1":{"id":"第2位","name":"sss","url":"./images/0.jpg"},
//			"2":{"id":"第3位","name":"sss","url":"./images/0.jpg"},
//			"3":{"id":"第4位","name":"sss","url":"./images/0.jpg"},
//			"4":{"id":"第5位","name":"sss","url":"./images/0.jpg"},
//			"5":{"id":"第6位","name":"sss","url":"./images/0.jpg"},
//		},
//		"4":{
//			"0":{"id":"第1位","name":"sss","url":"./images/0.jpg"},
//			"1":{"id":"第2位","name":"sss","url":"./images/0.jpg"},
//			"2":{"id":"第3位","name":"sss","url":"./images/0.jpg"},
//			"3":{"id":"第4位","name":"sss","url":"./images/0.jpg"},
//			"4":{"id":"第5位","name":"sss","url":"./images/0.jpg"},
//			"5":{"id":"第6位","name":"sss","url":"./images/0.jpg"},
//		},
//		"5":{
//			"0":{"id":"第1位","name":"sss","url":"img/0.jpg"},
//			"1":{"id":"第2位","name":"sss","url":"img/0.jpg"},
//			"2":{"id":"第3位","name":"sss","url":"img/0.jpg"},
//			"3":{"id":"第4位","name":"sss","url":"img/0.jpg"},
//			"4":{"id":"第5位","name":"sss","url":"img/0.jpg"},
//			"5":{"id":"第6位","name":"sss","url":"img/0.jpg"},
//		},
//		"6":{
//			"0":{"id":"第1位","name":"sss","url":"img/0.jpg"},
//			"1":{"id":"第2位","name":"sss","url":"img/0.jpg"},
//			"2":{"id":"第3位","name":"sss","url":"img/0.jpg"},
//			"3":{"id":"第4位","name":"sss","url":"img/0.jpg"},
//			"4":{"id":"第5位","name":"sss","url":"img/0.jpg"},
//			"5":{"id":"第6位","name":"sss","url":"img/0.jpg"},
//		},
//		"7":{
//			"0":{"id":"第1位","name":"sss","url":"img/0.jpg"},
//			"1":{"id":"第2位","name":"sss","url":"img/0.jpg"},
//			"2":{"id":"第3位","name":"sss","url":"img/0.jpg"},
//			"3":{"id":"第4位","name":"sss","url":"img/0.jpg"},
//			"4":{"id":"第5位","name":"sss","url":"img/0.jpg"},
//			"5":{"id":"第6位","name":"sss","url":"img/0.jpg"},
//		},
//		"8":{
//			"0":{"id":"第1位","name":"sss","url":"img/0.jpg"},
//			"1":{"id":"第2位","name":"sss","url":"img/0.jpg"},
//			"2":{"id":"第3位","name":"sss","url":"img/0.jpg"},
//			"3":{"id":"第4位","name":"sss","url":"img/0.jpg"},
//			"4":{"id":"第5位","name":"sss","url":"img/0.jpg"},
//			"5":{"id":"第6位","name":"sss","url":"img/0.jpg"},
//		},
//	};
    
    //alert(jsonDataObj[0][0]['id']);
    var info = jsonDataObj;
    
	var canclick = true;
	$(".content").on("click",".desk_wrap:not(:last)",function(e){
	  if(canclick){
		canclick = false;
		var _s = $(this);
		e.stopPropagation();
		if(!_s.attr("style")){_s.attr("style","");};
		var attr = $(this).attr("style");
		_s.siblings().css("display","none");
		_s.parent().siblings().filter(':not(".mask")').css("opacity","0");
		var offsetXY = _s.position();
		console.log(offsetXY);
		var offsetY =200- parseFloat(offsetXY.top),
			offsetX =110- parseFloat(offsetXY.left)
		console.log(offsetX);
		console.log(offsetY);
		if($(this).data("index")==0){
			$(this).transition(
			{
				"x":offsetX-100,
				"y":offsetY
			},
			300,
			function(){
				$(this).transition({"scale":2},300)
			}
		);
		}else{
			$(this).transition(
			{
				"x":offsetX,
				"y":offsetY
			},
			300,
			function(){
				$(this).transition({"scale":2.2},300)
			}
		);
		}
		
		$(".mask").show();
		//点击空白恢复原来大小
		$(".web").one("click",":not(.desk_wrap)",function(){
			canclick = true;
			//回复点击前的style
			$(".desk_wrap").attr("style",attr);
			$(".desk_wrap").css("display","inline-block");
			$(".desk_wrap[data-index=0]").css("display","block");
			$(".desk_wrap").parent().siblings().css("opacity","1");
			$(".mask").hide();
		})
	  }
	})
	//实现点击最后一个增加一张桌子
	$(".desk_wrap:last").on("click",function(e){
		e.stopPropagation();
		//判断是否除主宾坐外还有没有空位
//		function hasseated(){
//			$(".desk_s img").each(function(k,v){
//			if($(this).attr("src")=="images/seated_bg.png"){
//				return false;
//			}else{return true};
//		})
//		};
		//alert(hasseated());
//		if(hasseated()){
			var j = $(".desk_wrap").length-1;
			var clone = $(".desk_wrap").eq(1).clone();
			$(this).before(clone);
			//设置新增加桌子的index为当前长度
			clone.attr("data-index",$(".desk_wrap").length);
			//清空座位图片
			clone.find("img").attr("src","/Public/game/images/seated_bg.png");
			//改变圆桌内容
			clone.find(".cencir p").text("第"+j+"席");
//		}else{alert("还有空座位哦!")};
	})
	
	//为每个座位添加事件
	$(".content").on("click",".seated",function(e){
		e.stopPropagation();
		if($(this).find("img").attr("src")=="/Public/game/images/seated_bg.png"){
			var sel_index = $(this).parent(".seat").data("index");
			var fa_index = $(this).parents(".desk_wrap").data("index");
			console.log(fa_index,sel_index);
		console.log(info[fa_index][sel_index].url);
			$(this).find("img").attr("src",info[fa_index][sel_index].url)
			$(".fa_pos").text(fa_index);
			$(".sel_pos").text(sel_index+1);
		}else{
			alert("该座位已被预订,请重新选择!");
		}
	})
	//判断info信息里面桌子个数,桌子自动匹配
	function info_length(info){
		info.p
		var kk = 0;
		for(k in info){
			kk++
		}
		return kk;
		console.log(kk);
	}
	var info_length = info_length(info);
	while(info_length > $(".desk_wrap").length-1)
		{
			$(".desk_wrap:last").trigger("click");
		};
	
//点击移除进入时的遮罩
$(".remove").on("click",function(){
	$(".welcome").css("display","none");
});


//封装函数用于触发关闭遮罩
function swi(){
	$(".welcome").css("display","none");
};

//swi();





	
	
});
